﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Numerics;
using ReallyReallyReallySimpleRogueLike;
using ReallyReallyReallySimpleRoguelike.Managers;
using ReallyReallyReallySimpleRoguelike.Helpers;

namespace ReallyReallyReallySimpleRoguelike.Entities
{
    public class Monster : Creature
    {
        public Monster(Point p)
        {
            ImageCharacter = Constants.MonsterImage;
            Color = Constants.MonsterColor;
            X = p.X;
            Y = p.Y;
            Hits = Constants.StartingHitPoints;
        }

        //Refactor 13:MoveMonsterToPlayer. The monster should be in charge of where it moves.
        public void MoveToPlayer(Point playerLocation,IList<Monster> monsters)
        {

            Point move = new Point(X, Y);
            int tempX = X;
            int tempY = Y;

            ////move toward player
            //if (X > 0 && X < Constants.DungeonWidth && (X != playerLocation.X))
            //    tempX += (X > playerLocation.X) ? -1 : 1;
            ////move toward player
            //if ((Y > 0 && Y < Constants.DungeonHeight) && (Y != playerLocation.Y))
            //    tempY += (Y > playerLocation.Y) ? -1 : 1;

            //move on x axis toward player
            if (X != playerLocation.X)
                tempX += (X > playerLocation.X) ? -1 : 1;
            //move on y axis toward player
            if (Y != playerLocation.Y)
                tempY += (Y > playerLocation.Y) ? -1 : 1;

            DungeonLevel.ClampToDungeon(new Point(tempX,tempY));

            //This is why linq rocks so much - sh1t this is cool - man way cool!!!
            //its saying dont move to a spot unless there is no other monster
            if (!monsters.Any(m=>m.X == tempX && m.Y == tempY))
            {
                X = tempX;
                Y = tempY;
            }



        }
    }
}
